package com.zz.common

import java.time._

import pureconfig.ConfigReader.Result
import pureconfig.ConfigSource

object AppConfig {

  final case class App(timezone: String) {
    lazy val offset: ZoneOffset = zoneId.getRules.getOffset(Instant.now)
    lazy val zoneId: ZoneId     = ZoneId.of(timezone)
  }

  final case class Http(main: HttpConfig, akka: HttpConfig)

  final case class HttpConfig(port: Int, host: String)

  import pureconfig.generic.auto._

  def loadOrThrow(): AppConfig  = ConfigSource.default.loadOrThrow[AppConfig]
  def load(): Result[AppConfig] = ConfigSource.default.load[AppConfig]
}

import AppConfig._

final case class AppConfig(
                            app: App
                            , http: Http
                          )
